<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body>
<div id="app" class="container"  v-cloak>
    <div class="user-top-container">
      <div class="user-top-container-top">
        <div class="shop-avatar" v-myclick="clickUsername">
          <img :src="user.portrait || '../../image/portrait_moren.png'">
        </div>
        <div class="shop-title">
          <div class="shop-name" v-myclick="clickUsername">{{user.nickname || '点击登录'}}</div>
          <div class="shop-level">
            <span class="level_name_content" v-if="user.level_name">{{user.level_name}}</span>
          </div>
        </div>
        <div class="user-change" v-open-win v-myclick="makeprofit"  v-row-active.tapmode v-show="user.member_type=='2'">我要赚钱&nbsp;&nbsp;></div>
        <div class="user-change" v-open-win v-myclick="buyshop"  v-row-active.tapmode v-show="user.member_type=='5'">我要开店&nbsp;&nbsp;></div>
        <div class="user-change" v-open-win vurl="changeMember"  v-show="user.member_type=='6'">切换身份&nbsp;&nbsp;></div>
        <div class="user-profit-data" v-show="user.member_type!=='2'&&user.member_type">
          <div v-myclick="withdraw">
      <span class="data-count">{{user.balance|| 0 | double}}</span>
      <span class="data-title">可提金额</span>
    </div>
    <span></span>
    <div v-show="user.member_type=='5'">
      <span class="data-count" >{{user.unavaliable_calculate_commission || 0 | double}}</span>
      <span class="data-title">不可提现</span>
    </div>
    <span v-show="user.member_type=='5'"></span>
    <div v-show="user.member_type=='5'">
      <span class="data-count">{{user.sub_member_count_bshop || 0  }}</span>
      <span class="data-title">粉丝总数</span>
    </div>
    <div v-show="user.member_type=='6'" v-myclick="openIncomes">
      <span class="data-count">{{user.total_profit || 0 | double}}</span>
      <span class="data-title">累计收益</span>
    </div>
    <span v-show="user.member_type=='6'"></span>
    <div v-show="user.member_type=='6'" v-myclick="subshop">
      <span class="data-count">{{user.sub_member_count_bshop+user.sub_shop_count_l1}}</span>
      <span class="data-title">店铺规模</span>
    </div>
    <div v-show="user.member_type=='3'||user.member_type=='4'" v-myclick="submember">
      <span class="data-count">{{user.sub_member_count_all + parseInt(user.sub_shop_count_all)}}</span>
      <span class="data-title">我的团队</span>
    </div>
    <span v-show="user.member_type=='3'||user.member_type=='4'"></span>
    <div v-show="user.member_type=='3'||user.member_type=='4'" v-myclick="submember">
      <span class="data-count">{{user.sub_shop_count_l1?user.sub_shop_count_l1:0}}</span>
      <span class="data-title">直推店</span>
    </div>
    </div>
      </div>
    </div>
    <div class="user-middle-container" style="width:95%;margin:0 auto;margin-top:10px">
  <!-- <div class="user-middle-container-top" v-if="user.is_default_level=='0'">
      <span style="color: #ababab;font-size:12px">可提现收益(元)</span>
      <span style="font-size:20px;color: #e85407;padding-left:15px;">{{user.balance || 0 | double}}</span>
      <span class="user-span-right" :class="BSImg" v-myclick="withdraw">提现</span>
  </div> -->
  <div class="user-middle-container-bottom" v-show="user.member_type=='5'||user.member_type=='3'" >
  <div style="border-bottom:1px solid #eeeeee;border-right:1px solid #eeeeee">
    <span>{{user.cur_month_profit || 0 | double}}</span>
    <span>本月预估收益</span>
  </div>
  <div v-show="user.member_type=='3'" style="border-bottom:1px solid #eeeeee;border-right:1px solid #eeeeee">
    <span>{{user.cur_month_sub_shop_count_all || 0}}</span>
    <span>本月新增店主数</span>
  </div>
  <div style="border-bottom:1px solid #eeeeee">
    <span>{{user.wait_calculate_commission || 0 | double}}</span>
    <span>待结算收益</span>
  </div>
  <div v-myclick="openIncomes">
    <span>{{user.total_profit || 0 | double}}</span>
    <span>累计收益</span>
  </div>
  <div v-show="user.member_type=='5'" style="border-left:1px solid #eeeeee" v-if="user.is_default_level=='0'">
    <span>{{user.cur_month_consume || 0 | double}}/{{user.level_consume || 0 | double}}</span>
    <span>自消费</span>
  </div>
</div>
</div>
    <div class="user-bottom" v-if="user.level_id !== '7' && user.level_id !== '8'" style="width:95%;margin:0 auto;margin-top:10px;border-radius:8px">
        <div class="user-bottom-top">
            <span>我的订单</span>
            <span class="user-span-right" :class="BSImg" v-myclick="[0, openOrders]">查看全部</span>
        </div>
        <div class="user-bottom-bottom">
            <a v-myclick="[1, openOrders]">
                <img v-src="'../../image/user_btn_paid.png'">
                <p>已付款</p>
            </a>
            <a v-myclick="[2, openOrders]">
                <img v-src="'../../image/user_btn_received.png'">
                <p>已收货</p>
            </a>
            <a v-myclick="[3, openOrders]">
                <img v-src="'../../image/user_btn_settled.png'">
                <p>已失效</p>
            </a>
            <a v-myclick="[4, openOrders]">
                <img v-src="'../../image/user_btn_doing.png'">
                <p>处理中</p>
            </a>
        </div>
    </div>

    <!-- <div class="row-container" style="width:95%;margin:0 auto;margin-top:10px;border-radius:8px">
      <a v-myclick="initMeiQia" class="row row-line" v-row-active.tapmode>
         <img  class="row-arrow row-arrow-left" v-src="'../../image/user_icon_service.png'">
          <span class="user-setrow">客服</span>
          <img class="row-arrow row-arrow-right" v-src="'../../image/arrow_right_grey.png'">
      </a>
        <a v-open-win vurl="help" class="row row-line" v-row-active.tapmode style="display:none">
           <img  class="row-arrow row-arrow-left" v-src="'../../image/user_icon_help.png'">
            <span class="user-setrow">帮助</span>
            <img class="row-arrow row-arrow-right" v-src="'../../image/arrow_right_grey.png'">
        </a>
        <a v-myclick="[user.share, share]" class="row row-line" v-row-active.tapmode>
           <img  class="row-arrow row-arrow-left" v-src="'../../image/user_icon_invite.png'">
            <span class="user-setrow">邀请好友一起赚钱</span>
            <img class="row-arrow row-arrow-right" v-src="'../../image/arrow_right_grey.png'">
        </a>
    </div> -->

    <div class="user-bottom" v-if="user.level_id !== '7' && user.level_id !== '8'" style="width:95%;margin:0 auto;margin-top:10px;border-radius:8px">
        <div class="user-bottom-top">
            <span>必备工具</span>
        </div>
        <div class="user-bottom-bottom">
            <a v-myclick="[user.share, share]">
                <img v-src="'../../image/user_icon_share.png'">
                <p>分享有赏</p>
            </a>
            <a v-myclick="buyvip">
                <img v-src="'../../image/user_icon_vip.png'">
                <p>开通VIP</p>
            </a>
            <a v-myclick="shopcollect">
                <img v-src="'../../image/user_icon_collect.png'">
                <p>我的收藏</p>
            </a>
            <a v-myclick="initMeiQia">
                <img v-src="'../../image/user_icon_meiqia.png'">
                <p>联系客服</p>
            </a>
        </div>
    </div>

</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var user,
        qrcode,
        scanner,
        wx,
        qq,
        clipBoard,
        vm;

    var mq;
    apiready = function () {
        setBSImg();
        scanner = api.require('FNScanner');
        wx = api.require('wx');
        qq = api.require('QQPlus');
        MNActionButton = api.require('PIActionButton');
        clipBoard = api.require('clipBoard');
        mq = api.require('meiQia');
        if (getPrefs('token')) {
            showProgress();
            var data = {
                member_id: getPrefs('member_id')
            };
            var callback = function (ret) {
                user = ret.content;
                qrcode = user.qrcode;
                setPrefs('user', user);
                api.sendEvent({
                    name: 'getUnReadMsgCount',
                    extra: {count: user.unReadMessageCount}
                });
                encodeImg(qrcode);
            };
            pinet.post(URL.getUserinfo, data, callback);
        } else {
            user = {};
            qrcode = {};
            initApp();
            api.parseTapmode();
        }

        addListeners();
        setUserRefreshHeaderInfo(refresh);
    };

    function encodeImg(qrcode) {
        scanner.encodeImg({
            content: qrcode,
            saveImg: {
                path: 'fs://qrcode.png',
                w:400,
                h:400
            }
        }, function (ret) {
            qrcode = {};
            if(ret.status){
               qrcode = ret.imgPath;
            }
            initApp(qrcode);
            listenUpdUser(vm.user);
            api.parseTapmode();
        })
    }

    function initApp(qrcode) {
        vm = new Vue({
            el: '#app',
            data: {
                user: user,
                qrcode: qrcode,
                imgPath: '../../image/',
                appInstalled: {
                    wx: true,
                    qq: true,
                },
                BSImg: {
                    big: Vue.BSImg == 'big',
                    small: Vue.BSImg == 'small',
                },
            },
            methods: {
                clickUsername: function () {
                    if (!getPrefs('token')) {
                        reLogin();
                        return;
                    }
                    openWin('userinfo')

                },
                subshop: function(){
                  if (!getPrefs('token')) {
                      reLogin();
                      return;
                  }
                  openWin('subshop')
                },
                submember: function(){
                  if (!getPrefs('token')) {
                      reLogin();
                      return;
                  }
                  openWin('submember')
                },
                withdraw: function () {
                    if (!getPrefs('token')) {
                        reLogin();
                        return;
                    }
                    if(user.balance==0){
                      return;
                    }
                    openWin('withdraw');
                },
                makeprofit:function(){
                  if (!getPrefs('token')) {
                      reLogin();
                      return;
                  }
                  openWin('makeprofit');
                },
                buyshop:function(){
                  var attributes = {
                      type: 6
                  };
                  openWin('../user/addshop', {type: 6});
                },
                buyvip:function(){
                  if (!getPrefs('token')) {
                      reLogin();
                      return;
                  }
                  var attributes = {
                      type: 5
                  };
                  openWin('../user/addshop', {type: 5});
                },
                shopcollect:function(){
                  if (!getPrefs('token')) {
                      reLogin();
                      return;
                  }
                  if(user.member_type!=5){
                    alert('只对VIP用户开放');
                    return;
                  }
                  openWin('../shop/shopcollect');
                },
                openIncomes: function (keyState) {
                    if (!getPrefs('token')) {
                        reLogin();
                        return;
                    }
                    openWin('../ledger/total_income', {keyState: keyState || ''});
                },
                openOrders: function (state) {
                    if (!getPrefs('token')) {
                        reLogin();
                        return;
                    }
                    openWin('../order/my_order', {state: state});
                },
                initMeiQia: function () {
                    showMeiQia();
                },
                copyInvite: function (text) {
                    clipBoard.set({
                        value: text
                    }, function (ret) {
                        if (ret) {
                            api.toast({
                                msg: '已复制到剪贴板',
                            });
                        }
                    });
                },
                share: function (share) {
                    if(!getPrefs('token')){
                        reLogin();
                    }else{
                      onEvent('t005_c007','我的-邀请','');
                      attributes={};
                      var sharesuffix = {
                        eventId:'t005_c007_a001',
                        eventLable:'我的-邀请-分享',
                        attributes:attributes
                      }
                      openMNActionInviteButton(share,sharesuffix);
                    }
                    },
                share_wx: function (scene) {
                   var that = this;
                    if(!that.appInstalled.wx){
                      api.alert({
                          title: '提示',
                          msg: '未能检测到本地微信',
                          buttons: ['确定']
                      }, function (ret, err) {});
                    }else{
                      share_wx(scene, vm.user.share);
                    }
                },
                share_qq: function () {
                  var that = this;
                  if(!that.appInstalled.qq){
                    api.alert('未能检测到本地QQ');
                  }else{
                    share_qq(vm.user.share);
                  }
                },
            },
            created: function () {
                var that = this;
                wx.isInstalled(function (ret) {
                    that.appInstalled.wx = ret.installed;
                });
                qq.installed(function (ret) {
                    that.appInstalled.qq = ret.status;
                });
            }
        })
    }

    function refresh() {
        if (getPrefs('token')) {
            var data = {
                member_id: getPrefs('member_id')
            };
            var callback = function (ret) {
                user = ret.content;
                qrcode = user.qrcode;
                setPrefs('user', user);
                api.sendEvent({
                    name: 'getUnReadMsgCount',
                    extra: {count: user.unReadMessageCount}
                });

                if (vm) {
                    vm.user = user;

                    scanner.encodeImg({
                        content: qrcode,
                        saveImg: {
                            path: 'fs://qrcode.png',
                            w:400,
                            h:400
                        }
                    }, function (ret) {
                        vm.qrcode = {};
                        if(ret.status){
                            vm.qrcode = ret.imgPath;
                        }
                    });
                } else {
                    initApp();
                    api.parseTapmode();
                }
                api.refreshHeaderLoadDone();
            };
            var errback = function () {
                api.refreshHeaderLoadDone();
            };
            pinet.post(URL.getUserinfo, data, callback, errback);
        } else {
            api.refreshHeaderLoadDone();
        }

    }

    function addListeners() {
        api.addEventListener({
            name: 'reLogin'
        }, refresh);

        api.addEventListener({
            name: 'level_up'
        },
        function () {
            refresh();
        }
      );

        api.addEventListener({
            name: 'register'
        }, refresh);

        api.addEventListener({
            name: 'viewappear'
        }, function (ret, err) {
          if (getPrefs('token')) {
            user = JSON.parse(getPrefs('user'));
            if (user.hasPortraitUpd) {
                vm.user.portrait = user.portrait;
                user.hasPortraitUpd = false;
                setPrefs('user', user);
            }
          }
        });
    }

</script>
</html>
